package com.gem.day03;

import java.util.GregorianCalendar;
import java.util.Scanner;

public class SwitchDemo2 {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请您输入年份: ");
		int year = scanner.nextInt();
		if (year <= 0) {
			System.err.println("非法年份: " + year);
		} else {
			System.out.println("请您输入月份: ");
			int month = scanner.nextInt();
			int day = -1;
			//判断
			switch (month) {
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				day = 31;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				day = 30;
				break;
			case 2:
				if (new GregorianCalendar().isLeapYear(year)) {
					day = 29;
				} else {
					day = 28;
				}
			default:
				System.err.println("非法月份: " + month);
			}
			if (day != -1) {
				System.out.println(year + "年" + month + "月一共有: " + day + "天.");
			}

			/*
			 * JDK14新语法
			 * switch(month){
			 * 		case 1,3,5,7,8,10,12 -> day = 31;
			 * 		case 4,6,9,11 -> day = 30;
			 * 		...
			 * }
			 */
		}
		//关闭Scanner
		scanner.close();

		/*if(条件) {
			语句1;
		}else {
			语句2;
		}
		等价于:
		条件?语句1 : 语句2*/
	}
}
